package com.example.flow.hook;

import com.neuronbit.businessflow.runtime.Flow;
import com.neuronbit.businessflow.runtime.FlowContext;
import com.neuronbit.businessflow.runtime.lifecycle.FlowLifecycleHook;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class FlowHook implements FlowLifecycleHook {
    @Override
    public boolean support(FlowContext context, Flow flow) {
        return true;
    }

    @Override
    public void onStart(FlowContext context, Flow flow) {
        log.info("{} started", flow.getName());
    }

    @Override
    public void onEnd(FlowContext context, Flow flow) {
        log.info("{} end", flow.getName());
    }

    @Override
    public void onError(FlowContext context, Flow flow, Exception e) {
        log.error("{} error", flow.getName(), e);
    }

    @Override
    public void onPause(FlowContext flowContext, Flow flow) {
        log.error("{} onPause", flow.getName());
    }
}
